
#
"""
safe_dump(data,yaml对象) ：将Python对象转化为yaml格式并且输出到yaml文件中 ,但更加安全
"""

import yaml

data = {
    "color":['红色','蓝色','绿色'],
    "wx":{'pyq':"朋友圈",'lt':"聊天"},
    "languages": ["Ruby", "Perl", "Python"],
    "websites": {
        "YAML": "yaml.org",
        "Ruby": "ruby-lang.org",
        "Python": "python.org",
        "Perl": "use.perl.org"
    }
}

def save_yaml(data,filename):
    with open(filename,mode='w',encoding='utf-8') as f:
        yaml.safe_dump(data,f,allow_unicode=True,sort_keys=False)


if __name__ == '__main__':
    save_yaml(data,'demo2.yaml')